@ECHO.
@ECHO Deploying solution

:: Binary directory where all deployable components are stored
@SET DllSourcePath=Bin
:: Name of application to which BizTalk Project will be deployed to. 
:: This is name of application which you will see on BizTalk Administrator Console
@SET ApplicationName=My.Project
:: ProjectRoot is directory under which your entire solution is stored.
:: All directory, solution and project names are for illustrative purpose. You can change it as per your need.
:: Below are common BizTalk projects which are used for DLL Reference.
:: Assumption is DLL name is same as that of project name, which true by default. 
@SET SolutionName=My.Project.sln
@SET ComponentsName=My.Project.Components
@SET OrchestrationsName=My.Project.Orchestrations
@SET PipelineComponentsName=My.Project.PipelineComponents
@SET PipelinesName=My.Project.Pipelines
@SET SchemasName=My.Project.Schemas
@SET TransformsName=My.Project.Transforms
:: Name of biding files for different environments e.g. Dev, Sys, Test, Prelive, Live
@SET DevBinding=My.Project.BindingInfo.Dev
@SET SysBinding=My.Project.BindingInfo.Sys
@SET TestBinding=My.Project.BindingInfo.Test
@SET PreliveBinding=My.Project.BindingInfo.Prelive
@SET LiveBinding=My.Project.BindingInfo.Live
:: 64 Bit .net 4.0 root directory, if you have 32 bit machine then use Framework instead of Framework64
@SET FilePath64Bit=C:\Windows\Microsoft.NET\Framework64\v4.0.30319
:: BizTalk rule with Vocabulary and Policy details
@SET RulesXml=My.Project.Policy.Rules.xml


:: BizTalk Application creation step, if it is present already, error will be thrown but deployment will continue
@btstask AddApp -ApplicationName:%ApplicationName%
:: GACUtil path read from registry
SET GACUTILPATH=
FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0A\WinSDK-NetFx40Tools-x86" /v InstallationFolder') DO SET GACUTILPATH=%%B
echo %GACUTILPATH%
:: GAC Dlls of all projects
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%ComponentsName%.dll" 
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%PipelineComponentsName%.dll" 
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%SchemasName%.dll" 
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%TransformsName%.dll" 
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%PipelinesName%.dll" 
"%GACUTILPATH%\gacutil.exe" /i ".\%DllSourcePath%\%OrchestrationsName%.dll" 

:: Add .net assemblies to BizTalk application as resource
:: Keep options list as it is. It will be useful when you export application and install somewhere else.
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:Assembly  -Source:".\%DllSourcePath%\%ComponentsName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite  
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:Assembly  -Source:".\%DllSourcePath%\%PipelineComponentsName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite 
:: Add BizTalk assemblies to BizTalk application as resource
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BizTalkAssembly  -Source:".\%DllSourcePath%\%SchemasName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BizTalkAssembly  -Source:".\%DllSourcePath%\%TransformsName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BizTalkAssembly  -Source:".\%DllSourcePath%\%PipelinesName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BizTalkAssembly  -Source:".\%DllSourcePath%\%OrchestrationsName%.dll" -Options:GacOnAdd,GacOnImport,GacOnInstall -Overwrite 

:: Add all binding files to BizTalk Application
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BiztalkBinding  -Source:".\%DllSourcePath%\%DevBinding%.xml" -Overwrite -Property:TargetEnvironment=DEV 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BiztalkBinding  -Source:".\%DllSourcePath%\%SysBinding%.xml" -Overwrite -Property:TargetEnvironment=SYS 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BiztalkBinding  -Source:".\%DllSourcePath%\%TestBinding%.xml" -Overwrite -Property:TargetEnvironment=TEST 
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BiztalkBinding  -Source:".\%DllSourcePath%\%PreliveBinding%.xml" -Overwrite -Property:TargetEnvironment=PRELIVE
@btstask -ApplicationName:%ApplicationName% AddResource -Type:System.BizTalk:BiztalkBinding  -Source:".\%DllSourcePath%\%LiveBinding%.xml" -Overwrite -Property:TargetEnvironment=LIVE

:: Step to register .net component dll with COM+ for enlisting transaction. 
:: If you dont have any COM+ component in dll then you can skip this
ECHO 
ECHO Registering Components dll with COM+
%FilePath64Bit%\RegSvcs.exe ".\%DllSourcePath%\%ComponentsName%.dll"

:: Creating SSO Application and updating values
:: ConfigStore.xml is SSO Configuration Application file
:: BTSScnSSOApplicationConfig executable should be within Bin directory, it will be used to update values of SSO Config App fields
echo "Creating SSO Application"
%ENTSSOManage% -CreateApps ".\%DllSourcePath%\ConfigStore.xml"
echo "Updating SSO Application field"
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig Login "BIZTALK_USER" 
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig Password temp1234 
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig Pooling true 
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig Server ORACLEDEV
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig Port 1551
%DllSourcePath%\BTSScnSSOApplicationConfig.exe -set IDSDatabase IDSDatabaseConfig ServiceName DEV1

:: Import Vocabulary and Policy to BizTalk Rule Engine database and deploy
%DllSourcePath%\ImportExportRuleStore.exe" -i ".\%DllSourcePath%\%RulesXml%"

pause;
